import 'package:freedom/page/mahjong/common/mahjong_context.dart';
import 'package:freedom/page/mahjong/common/message_content.dart';
import 'package:freedom/page/mahjong/event/disk_direction_update.dart';
import 'package:freedom/page/mahjong/event/room_inf_update.dart';
import 'package:freedom/page/mahjong/event/user_touch_card.dart';
import 'package:freedom/page/mahjong/message/abstract_action_message.dart';

class TouchCard extends AbstractMessageActionHandler<MahjongMessage> {
  /**
   *    这里有3个逻辑
   * 1. 有人摸牌的话 桌面棋牌总数减少
   * 2. 东南西北风指向问题
   * 3. 东南西北风倒计时问题
   */
  @override
  void doMessage(MahjongMessage message) {
    var sourceUserId = message.exeActionUid;

    // 更改桌面 东南西北
    MahjongContext.postRoomEvent<DiskDirectionUpdate>(DiskDirectionUpdate(
        MahjongContext.getUserStateById(sourceUserId)!.direction));
    // 发布用户摸牌事件
    MahjongContext.postUserEvent<UserTouchCardEvent>(
        sourceUserId, UserTouchCardEvent(message.cardCode));
    // 发布房间用户摸牌事件
    MahjongContext.roomInfo.gameInfo.residue--;
    MahjongContext.postRoomEvent<RoomInfoUpdateEvent>(
        RoomInfoUpdateEvent(MahjongContext.roomInfo));
  }
}
